#!/usr/bin/perl
# to select the overlap portion of 1_flow_table.csv, in particular, when sending rate of flow1 > flow

#folders
$root_folder="/root/switch_project";
$result_folder="$root_folder/experiment/exp16"; #root dir to store experimental resutls


$runs=2; # number of repeated experiment (same setting)

@speed;

#specify sending rate
$start_sending_rate=100;#Mb/s
$end_sending_rate=1000;
$sending_rate_gap=100;

#calculate speed and gap (gap is not used for now)
for($b=$start_sending_rate, $a=0; $b<=$end_sending_rate; $b+=$sending_rate_gap, $a++)
{
	$speed[$a]=$b;
}


for($j=0; $j<=$#speed; $j++)
{
	for($k=0; $k<=$#speed; $k++)
	{
		for($i=1; $i<=$runs; $i++)
		{	
			chdir "$result_folder/$speed[$j]M/$speed[$k]M/$i";
			print "folder = $result_folder/$speed[$j]M/$speed[$k]M/$i\n";

			$input = "1_flow_table_overlap.csv";
			$output = "1_flow_pure_delay.txt";
	
			open(INPUT1, $input) or die "$input cannot be opened.\n";
			open(OUTPUT1, ">$output") or die "$output cannot be created.\n";
	

			while(<INPUT1>)
			{
				$line=$_;
				chomp($line);
				@block = split(", ", $line);
				
				if($block[3]!=0)
				{		
					print OUTPUT1 "$block[3]\n";
				}
				
					
			}

			close(INPUT1);
			close(OUTPUT1);
		}
	}
}

chdir "$root_folder/script";
